package cassys.actions.moduleManagement;

import cassys.ejb.clients.ModuleManagementDelegate;
import com.opensymphony.xwork2.ActionSupport;
import cassys.domain.classManagement.*;
import java.util.List;

/**
 *
 * @author User
 */
public class CreateModule extends ActionSupport {

  

    private ModuleManagementDelegate moduleDelegate;
    private ModuleType moduleType;
    private String moduleCode;
    private String moduleTitle;
    private Lecture owner;
    
    private List<ModuleType> moduleTypes;
    private List<Lecture> lecturers;

    public CreateModule() {
        moduleDelegate = new ModuleManagementDelegate();

    }

    @Override
    public String execute() throws Exception {
        System.out.println("module management action started :)");
        setLecturers(moduleDelegate.getAllLecturers());
        setModuleTypes(moduleDelegate.getModuleTypes());
        System.out.println("got the lecturers");
        return SUCCESS;
    }

    public String createNewModule() throws Exception {
        System.out.println("invoke create module action");
        moduleDelegate.crateModule(getNewModule());
        
        return SUCCESS;
    }

    private Module getNewModule() {
        Module newModule = new Module(getModuleCode(), getModuleTitle(), getModuleType(), getOwner());
        for (Lecture lecture : lecturers) {
            newModule.addLecture(lecture);
        }
        System.out.println("New Module"+  getOwner().toString());
        return newModule;
    }

    /**
     * @return the moduleType
     */
    public ModuleType getModuleType() {
        return moduleType;
    }

    /**
     * @param moduleType the moduleType to set
     */
    public void setModuleType(ModuleType moduleType) {
        this.moduleType = moduleType;
    }

    /**
     * @return the moduleCode
     */
    public String getModuleCode() {
        return moduleCode;
    }

    /**
     * @param moduleCode the moduleCode to set
     */
    public void setModuleCode(String moduleCode) {
        this.moduleCode = moduleCode;
    }

    /**
     * @return the moduleTitle
     */
    public String getModuleTitle() {
        return moduleTitle;
    }

    /**
     * @param moduleTitle the moduleTitle to set
     */
    public void setModuleTitle(String moduleTitle) {
        this.moduleTitle = moduleTitle;
    }

    /**
     * @return the owner
     */
    public Lecture getOwner() {
        return owner;
    }

    /**
     * @param owner the owner to set
     */
    public void setOwner(Lecture owner) {
        this.owner = owner;
    }

    /**
     * @return the lecturers
     */
    public List<Lecture> getLecturers() {
        return lecturers;
    }

    /**
     * @param lecturers the lecturers to set
     */
    public void setLecturers(List<Lecture> lecturers) {
        this.lecturers = lecturers;
    }

    /**
     * @return the moduleTypes
     */
    public List<ModuleType> getModuleTypes() {
        return moduleTypes;
    }

    /**
     * @param moduleTypes the moduleTypes to set
     */
    public void setModuleTypes(List<ModuleType> moduleTypes) {
        this.moduleTypes = moduleTypes;
    }

   
}
